const  parseSpecifiedUrlParams = (url, key = null) => {
  let offset = url.indexOf("?");
  if (offset !== -1) {
    url = url.substr(offset);
  }
  let pairs;
  let params = {};
  if (url) {
    url = url.substr(1);
    pairs = url.split("&");
    for (let pair of pairs) {
      let list = pair.split("=");
      if (list.length == 2) {
        params[list[0]] = list[1];
      }
    }
  }

  if (key) {
    if (params[key] === undefined) {
      return null;
    } else {
      return params[key];
    }
  } else {
    return params;
  }
}

const parseUrlParams = (key = null) => {
  let search = window.location.href;
  return parseSpecifiedUrlParams(search, key);
}


export {
  parseUrlParams
}
